<?php

namespace App\Admin\Controllers;

use App\Admin\Model\InvitationCeremony;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class InvitationCeremonyController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(InvitationCeremony::class, function (Grid $grid) {

            $grid->id('ID')->sortable();
            $grid->status('状态')->display(function($status){
                switch ($status) {
                    case 1:
                        return 'yes';
                        break;
                    
                    default:
                        return '我也不知道的状态';
                        break;
                }
            });
            
            $grid->uid_nackname('邀请人')->display(function($uid_nackname){
                // dd($uid_nackname['nickname']);
                if(!empty($uid_nackname)){
                    return $uid_nackname['nickname']? $uid_nackname['nickname'] : '查无此人..';
                }else{
                    return $uid_nackname['mobile'] ? $uid_nackname['mobile'] : '查无此人..';
                }
                
            });
            $grid->mobile('手机号')->label('info');;
            $grid->created_at('创建时间');
            $grid->updated_at('更新时间');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(InvitationCeremony::class, function (Form $form) {

            $form->display('id', 'ID');
            $form->display('mobile', '手机号');
            $form->display('created_at', '创建时间');
            $form->display('updated_at', '更新时间');
        });
    }
}
